import { getCategory } from '@/api/category'
import { ALL_CATEGORY_ITEM } from '@/constants'

export default {
  // 独立作用域
  namespaced: true,
  state: () => ({
    categorys: [],
    currentIndex: 0, // 修正拼写错误
    currentCategoryId: ALL_CATEGORY_ITEM.id // 新增
  }),
  mutations: {
    setCategorys(state, categorys) {
      state.categorys = [ALL_CATEGORY_ITEM, ...categorys]
    },
    setCurrentIndex(state, currentIndex) {
      // 修正拼写错误
      state.currentIndex = currentIndex // 修正拼写错误
      // console.log(state.currentIndex)
    },
    setCurrentCategoryId(state, currentCategoryId) {
      state.currentCategoryId = currentCategoryId // 新增
 
      
    }
  },
  actions: {
    async useCategoryData(context) {
      const { categorys } = await getCategory()
      context.commit('setCategorys', categorys)
    }
  }
}
